﻿<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="DynamicReport.aspx.cs" Inherits="DynamicReport" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>报表模板</title>
    <script src="js/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="js/extTools.js" type="text/javascript"></script>
    <script src="js/config.js" type="text/javascript"></script>
    <link href="css/ExtStyle.css" rel="stylesheet" type="text/css" />
    <script>
        //        Ext.onReady(function () {
        //            //加载网格列
        //            var mid = getUrlParam("mid");
        //            Ext.Ajax.request({
        //                url: url_path + "/Default.aspx?method=getDynColumn",
        //                params: { mid: mid },
        //                success: function (response, option) {
        //                    var msg = Ext.util.JSON.decode(response.responseText);
        //                    if (Ext.getCmp("GridPanel1") != undefined) {
        //                        Ext.getCmp("GridPanel1").destroy();
        //                    }
        //                    if (Ext.getCmp("Store1") != undefined) {
        //                        Ext.getCmp("Store1").remove();
        //                    }
        //                    var store = new Ext.data.JsonStore({
        //                        id: "Store1",
        //                        fields: msg.fieldNames
        //                    });
        //                    var cm = new Ext.grid.ColumnModel(msg.colName);
        //                    Ext.getCmp("GridPanel1") = new Ext.grid.GridPanel({
        //                        id: "GridPanel1",
        //                        ttile:"测试",
        //                        cm: cm,
        //                        ds: store
        //                    });
        //                    grid.render("TabPanel1");
        //                }
        //            });

        //        });

        var getTasks = function () {
            var vals = "";
            var msg = "",
                selChildren = App.TreePanel1.getChecked();

            Ext.each(selChildren, function (node) {
                if (msg.length > 0) {
                    msg += ", ";
                    vals += ", "
                }

                msg += node.data.text;
                vals += node.data.id;
            });

            //            Ext.Msg.show({
            //                title: "Completed Tasks",
            //                msg: msg.length > 0 ? msg : "None",
            //                icon: Ext.Msg.INFO,
            //                minWidth: 200,
            //                buttons: Ext.Msg.OK
            //            });
            Ext.getCmp('txtShowColums').setValue(msg);
            App.HD_Fiels.setValue(vals);
            App.Window1.close();
        };
        var getContrlStr = function (obj) {
            var vals="";
            obj.items.each(function (item, index, length) {
                if (item.getXType() != "netlabel") {
                    var temp = item.getValue();
                    if (temp == null || temp == '') {
                        temp = " ";
                    }
                    if (item.getXType() == "datefield") {
                        vals += Ext.util.Format.date(item.getValue(), 'Y-m-d') + "#";
                    } else if (item.getXType() == "netmulticombo" && temp != " ") {
                        //var aa = new Array();
                        var aa = (temp + ",").split(",");
                        var ss = "(";
                        for (var i = 0; i < aa.length - 1; i++) {
                            if (aa[i] != "")
                                ss += "''" + aa[i] + "'',";
                        }
                        ss = ss.substring(0, ss.length - 1) + ")";
                        vals += ss + "#";
                    } else
                        vals += temp + "#";
                }
            });
            //fields = fields.substring(0, fields.length - 1);
            vals = vals.substring(0, vals.length - 1);
            return vals;
        };

        var finddata = function (obj) {
            if (obj.getForm().isValid()) {
                Ext.Msg.show({
                    message: "正在加载报表, 请稍等...",
                    progressText: "数据加载中...",
                    width: 300,
                    wait: true,
                    waitConfig: {
                        interval: 200
                    },
                    iconCls: "ext-mb-download"
                });
                var param = getContrlStr(obj);
                CompanyX.BtnFind(param, {
                    timeout: 300000,
                    success: onSuccess,
                    failure: onFailure
                    //eventMask: { showMask: true }
                });
                function onSuccess() {
                    setTimeout(function () {
                        Ext.MessageBox.hide();
                        Ext.Msg.notify('完成', '报表已加载完成!');
                    }, 500);
                }
                function onFailure() {
                    Ext.Msg.show({
                        title: "温馨提示",
                        msg: "数据查询出现问题！",
                        icon: Ext.Msg.INFO,
                        minWidth: 200,
                        buttons: Ext.Msg.OK
                    });
                }
            }
        }
        var dataOutExcel = function (obj) {
            if (obj.getForm().isValid()) {
                var param = getContrlStr(obj);
                CompanyX.OutExcel(param, {
                    timeout: 300000,
                    eventMask: { showMask: true,msg:"玩命下载中..." }
                });
            }
        }
        /*
        var finddata = function (obj) {
            if (obj.getForm().isValid()) {
                Ext.Msg.show({
                    message: "正在加载报表, 请稍等...",
                    progressText: "数据加载中...",
                    width: 300,
                    wait: true,
                    waitConfig: {
                        interval: 200
                    },
                    iconCls: "ext-mb-download"
                });
                var fields = "";
                var vals = "";
                var str;
                //            if (App.HD_Fiels.getValue() == "") {
                //                Ext.Msg.show({
                //                    title: "温馨提示",
                //                    msg: "请选择输出项目！",
                //                    icon: Ext.Msg.INFO,
                //                    minWidth: 200,
                //                    buttons: Ext.Msg.OK
                //                });
                //                return;
                //            }
                obj.items.each(function (item, index, length) {
                    if (item.getXType() != "netlabel") {
                        //alert(item.getXType());
                        var temp = item.getValue();
                        if (temp == null || temp == '') {
                            temp = " ";
                        }
                        str = item.initialConfig.id;

                        fields += str.substring(3, str.length) + "#";
                        if (item.getXType() == "datefield") {
                            vals += Ext.util.Format.date(item.getValue(), 'Y-m-d') + "#";
                        } else if (item.getXType() == "netmulticombo" && temp != " ") {
                            //var aa = new Array();
                            var aa = (temp + ",").split(",");
                            var ss = "(";
                            for (var i = 0; i < aa.length - 1; i++) {
                                if (aa[i] != "")
                                    ss += "''" + aa[i] + "'',";
                            }
                            ss = ss.substring(0, ss.length - 1) + ")";
                            vals += ss + "#";
                        } else
                            vals += temp + "#";
                    }
                });


                fields = fields.substring(0, fields.length - 1);
                vals = vals.substring(0, vals.length - 1);

                CompanyX.BtnFind(fields, vals, {
                    timeout: 0,
                    success: onSuccess,
                    failure: onFailure
                    //eventMask: { showMask: true }
                });
                function onSuccess() {
                    setTimeout(function () {
                        Ext.MessageBox.hide();
                        Ext.Msg.notify('完成', '报表已加载完成!');
                    }, 500);
                }

                function onFailure() {
                    Ext.Msg.show({
                        title: "温馨提示",
                        msg: "数据查询出现问题！",
                        icon: Ext.Msg.INFO,
                        minWidth: 200,
                        buttons: Ext.Msg.OK
                    });
                }
                //CompanyX.BtnFind(fields, vals);
            }*/
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Crisp" />
        <ext:Viewport ID="Viewport1" runat="server">
            <LayoutConfig>
                <ext:HBoxLayoutConfig Align="Stretch" />
            </LayoutConfig>
            <Defaults>
                <ext:Parameter Name="margin" Value="0" Mode="Value" />
            </Defaults>
            <Items>
                <ext:Panel ID="Panel1" runat="server" Flex="1" Layout="FitLayout">
                    <Items>
                        <ext:Panel ID="Panel2" runat="server" Layout="BorderLayout">
                            <Items>
                                <ext:Panel Region="West" ID="Panel3" runat="server" Split="true" Collapsible="true"
                                    Collapsed="false" Title="统计过虑条件" Icon="ApplicationFormEdit" PaddingSummary="5px 5px 0"
                                    Width="280" ButtonAlign="Center" Layout="BorderLayout">
                                    <Items>
                                        <ext:Panel runat="server" Title="输出条件" Layout="Column" Margin="3" Region="North" Visible ="false"
                                            Collapsible="true">
                                            <Items>
                                                <ext:TextArea ID="txtShowColums" runat="server" FieldLabel="输出项目" LabelWidth="60"
                                                    Height="80" Padding="3" ReadOnly="true">
                                                </ext:TextArea>
                                                <ext:Button runat="server" Text="设置">
                                                    <Listeners>
                                                        <Click Handler="#{Window1}.show();">
                                                        </Click>
                                                    </Listeners>
                                                </ext:Button>
                                            </Items>
                                        </ext:Panel>
                                        <ext:FormPanel ID="ColumPanel" runat="server" Layout="Column" Reference="form" Region="Center"
                                            Collapsible="true" ButtonAlign="Center" Title="基本条件" Margin="3" BodyStyle="overflow:auto;">
                                            <Items>
                                            </Items>
                                        </ext:FormPanel>
                                    </Items>
                                    <BottomBar>
                                        <ext:Toolbar ID="Toolbar1" runat="server">
                                            <Items>
                                                <ext:Button ID="Button10" runat="server" Text="统计" IconCls="find24" Scale="Small"
                                                    IconAlign="Left" Cls="x-btn-as-arrow">
                                                    <Listeners>
                                                        <Click Handler="finddata(#{ColumPanel});">
                                                        </Click>
                                                    </Listeners>
                                                </ext:Button>
                                                <ext:Button ID="Button8" runat="server" Text="导出" IconCls="import24" Scale="Small" Visible ="false"
                                                    IconAlign="Left" Cls="x-btn-as-arrow">
                                                    <Listeners>
                                                        <Click Handler="exportData('xls');" />
                                                    </Listeners>
                                                </ext:Button>
                                                 <ext:Button ID="Button3" runat="server" Text="导出" IconCls="import24" Scale="Small"
                                                    IconAlign="Left" Cls="x-btn-as-arrow">
                                                  <Listeners>
                                                    <Click Handler="dataOutExcel(#{ColumPanel});" />
                                                  </Listeners>
                                                </ext:Button>
                                            </Items>
                                        </ext:Toolbar>
                                    </BottomBar>
                                </ext:Panel>
                                <ext:TabPanel ID="TabPanel1" runat="server" Region="Center">
                                    <Items>
                                        <ext:GridPanel ID="GridPanel1" runat="server" TitleAlign="Center" Title="数据列表" ActiveIndex="0">
                                            <TopBar>
                                                <ext:Toolbar ID="Toolbar2" runat="server" Layout="Container">
                                                    <Items>
                                                        <ext:Toolbar ID="Toolbar8" runat="server">
                                                            <Items>
                                                                <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="排序区域:" Reorderable="false" />
                                                                <ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server" Reorderable="false" />
                                                            </Items>
                                                            <Plugins>
                                                                <ext:BoxReorderer ID="BoxReorderer1" runat="server">
                                                                    <Listeners>
                                                                        <Drop Handler="changeSortDirection(dragCmp, false);" />
                                                                    </Listeners>
                                                                </ext:BoxReorderer>
                                                                <ext:ToolbarDroppable ID="ToolbarDroppable1" runat="server">
                                                                    <CreateItem Fn="createItem" />
                                                                    <CanDrop Fn="canDrop" />
                                                                    <Listeners>
                                                                        <Drop Fn="doSort" />
                                                                    </Listeners>
                                                                </ext:ToolbarDroppable>
                                                            </Plugins>
                                                        </ext:Toolbar>
                                                    </Items>
                                                </ext:Toolbar>
                                            </TopBar>
                                            <Store>
                                                <ext:Store ID="Store1" runat="server" PageSize="100" OnReadData="RefreshDataSet"
                                                    OnSubmitData="Store1_Submit" IsUpload="true">
                                                    <Model>
                                                        <ext:Model ID="Model2" runat="server">
                                                        </ext:Model>
                                                    </Model>
                                                </ext:Store>
                                            </Store>
                                            <ColumnModel>
                                                <Columns>
                                                </Columns>
                                            </ColumnModel>
                                            <View>
                                                <ext:GridView ID="GridView1" runat="server" StripeRows="true" TrackOver="true" />
                                            </View>
                                            <Features>
                                                <ext:Summary ID="Summary1" runat="server">
                                                </ext:Summary>
                                            </Features>
                                            <SelectionModel>
                                                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                                            </SelectionModel>
                                            <BottomBar>
                                                <ext:PagingToolbar ID="PagingToolbar1" runat="server">
                                                    <Items>
                                                        <ext:Label ID="Label2" runat="server" Text="每页显示:" />
                                                        <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                                                        <ext:ComboBox ID="ComboBox1" runat="server" Width="80">
                                                            <Items>
                                                                <ext:ListItem Text="100" />
                                                                <ext:ListItem Text="200" />
                                                                <ext:ListItem Text="500" />
                                                                <ext:ListItem Text="1000" />
                                                            </Items>
                                                            <SelectedItems>
                                                                <ext:ListItem Value="100" />
                                                            </SelectedItems>
                                                            <Listeners>
                                                                <Select Handler="#{GridPanel1}.store.pageSize = parseInt(this.getValue(), 10); #{GridPanel1}.store.reload();" />
                                                            </Listeners>
                                                        </ext:ComboBox>
                                                    </Items>
                                                    <Plugins>
                                                        <ext:ProgressBarPager ID="ProgressBarPager1" runat="server" />
                                                    </Plugins>
                                                </ext:PagingToolbar>
                                            </BottomBar>
                                            <Listeners>
                                                <AfterLayout Handler="#{ToolbarDroppable1}.addDDGroup(this.child('headercontainer').reorderer.dragZone.ddGroup); doSort();"
                                                    Single="true" />
                                            </Listeners>
                                        </ext:GridPanel>
                                    </Items>
                                </ext:TabPanel>
                            </Items>
                        </ext:Panel>
                    </Items>
                </ext:Panel>
                <ext:Hidden ID="ActState" runat="server" ClientIDMode="Static" Text="Edit" />
            </Items>
        </ext:Viewport>
        <ext:Window ID="Window1" runat="server" Icon="Accept" Title="选择输出项目" Layout="FitLayout"
            Height="350" Width="600" Hidden="true">
            <Items>
                <ext:TreePanel ID="TreePanel1" runat="server" Height="400" Width="250" UseArrows="true"
                    AutoScroll="true" Animate="true" RootVisible="false">
                    <Root>
                        <ext:Node>
                            <Children>
                                <ext:Node Text="报表输出项" Icon="Folder">
                                    <Children>
                                    </Children>
                                </ext:Node>
                            </Children>
                        </ext:Node>
                    </Root>
                    <Listeners>
                        <CheckChange Handler="var node = Ext.get(this.getView().getNode(item));
                                      node[checked ? 'addCls' : 'removeCls']('complete')" />
                        <Render Handler="this.getRootNode().expand(true);" Delay="50" />
                    </Listeners>
                    <Buttons>
                        <ext:Button ID="Button1" runat="server" Text="确定" Icon="Accept" UI="Info">
                            <Listeners>
                                <Click Fn="getTasks" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="Button2" runat="server" Text="取消" Icon="Cancel" UI="Warning">
                            <Listeners>
                                <Click Handler="#{Window1}.close();" />
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                </ext:TreePanel>
            </Items>
        </ext:Window>
        <ext:Hidden ID="HD_Fiels" runat="server" ClientIDMode="Static" Text="" />
        <ext:Hidden ID="FormatType" runat="server" />
    </div>
    </form>
</body>
</html>
